<template>
  <transition name="slide">
    <div class="singer-detail">
      <music-list :songs="songs" :title="title" :bg-image="bgImage"></music-list>
    </div>
  </transition>
</template>

<script type="text/javascript">
import { mapGetters } from 'vuex'
import { getSingerDetail } from '@/api/singer'
import { ERR_OK } from '@/common/js/common'
import { createSong } from '@/common/js/song'
import MusicList from '@/components/music-list/music-list'
export default {
  name: 'SingerDetall',
  computed: {
    ...mapGetters([
      'singer'
    ]),
    title () {
      console.log(999)
      return this.singer.name
    },
    bgImage () {
      return this.singer.avatar
    }
  },
  data () {
    return {
      songs: []
    }
  },
  watch: {
    $route () {
      // console.log(9)
      if (this.$route) {
        this._getDetail()
      }
    }
  },
  methods: {
    // 获取歌手详情
    _getDetail () {
      if (!this.singer.id) {
        this.$router.push('/singer')
        return
      }
      getSingerDetail(this.singer.id).then((res) => {
        if (res.status === ERR_OK) {
          // console.log(res)
          this.songs = this._normalizeSongs(res.data.hotSongs)
          console.log(this.songs)
        }
      })
    },
    _normalizeSongs (list) {
      var ret = []
      list.forEach((item) => {
        ret.push(createSong(item))
      })
      return ret
    }
  },
  mounted () {
    // console.log(99)
    // console.log(this.singer)
    this._getDetail()
  },
  components: {
    MusicList: MusicList
  }
}
</script>

<style lang="less" scoped>
@import '~@/common/stylus/variable.less';
/*.singer-detail {
  position: fixed;
  z-index: 1111;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: @color-background;
}*/

.slide-enter-active, .slide-leave-active {
  transition: all 0.3s
}
</style>
